export function download(blob, fileName) {
  const elink = document.createElement("a");
  elink.download = fileName;
  elink.style.display = "none";
  elink.href = URL.createObjectURL(blob);
  document.body.appendChild(elink);
  elink.click();
  URL.revokeObjectURL(elink.href);
  document.body.removeChild(elink);
}

export function getFileSize(size) {
  if (!size) return "0 B";
  const num = 1024.0; //byte
  if (size < num) return size + " B";
  if (size < Math.pow(num, 2)) return (size / num).toFixed(2) + " KB"; //kb
  if (size < Math.pow(num, 3))
    return (size / Math.pow(num, 2)).toFixed(2) + " MB"; //M
  if (size < Math.pow(num, 4))
    return (size / Math.pow(num, 3)).toFixed(2) + " G"; //G
  return (size / Math.pow(num, 4)).toFixed(2) + " T"; //T
}
